<?php
/**
 * @fileoverview    封装我收到的评论显示模块数据
 * @author          gaojian3
 * @date            2012.02.14
 * @copyright       sina meila
 * @param           $aRows   评论数组
 * @return             $data
 */


class ml_biz_comOutput {
    
    private $_uids;
    private $_pic_ids;
    private $_nicks;
    private $_personUrls;
    private $_personPics;
    private $_goodUrls;
    private $_pic_urls;
    private $oContent;
    private $oUserFeed;
    private $ordsCount;
    private $_cont_rids;
    
    public function __construct(){
        $this->oContent=new ml_model_dbContent();
        $this->oUserFeed=new ml_model_dbUserfeed();
    }
  
    public function getComHtml($aRows){
        foreach($aRows as  &$val ){
            $val['content']=ml_tool_formatContent::format_content($val['content']);
            if(ml_tool_resid::resid2type($val['rid']) == ML_RESID_TYPE_CONTENT)
                $this->_cont_rids[]=$val['rid'];
            if(ml_tool_resid::resid2type($val['rid']) == ML_RESID_TYPE_USERFEED){
                $feedRids[]=$val['rid'];
                if($val['content_rid']){
                    $this->_cont_rids[]=$val['content_rid'];
                }
            }
            unset($val);
        }
        
        $feedData=$this->oUserFeed->getUserfeedByRids($feedRids);
        foreach($feedData as $val){
            if($val['content_rid']){
                   $this->_cont_rids[]=$val['content_rid'];
            }
        }
        $this->_cont_rids=array_unique($this->_cont_rids);
        $rids=array_merge($feedRids,$this->_cont_rids);
        $count=$this->getComCountNum($rids);
        $this->getIds($aRows);
        
        $this->contData=$this->oContent->get_content_by_rids($this->_cont_rids);
        
        $this->getIds($this->contData);
        $this->getIds($feedData);
        
        $this->_uids[]=$uid;
        $this->_nicks=ml_tool_nick::uids2nicks(array_unique($this->_uids));
        
        $feedData=$this->getFeedContent($feedData);
        $this->contData=$this->getContData($this->contData);
        $this->getPersonUrls(array_unique($this->_uids));
        $this->getPersonPics(array_unique($this->_uids));
        $this->getPicUrls(array_unique($this->_pic_ids));
        
        
        $this->getGoodUrls($this->_cont_rids);
        $this->getGoodPrice($this->_cont_rids);
        $this->getGoodTitle($this->_cont_rids);
        foreach($aRows as $val){
            if(ml_tool_resid::resid2type($val['rid'])==ML_RESID_TYPE_CONTENT)
                $val['comData']=$this->contData[$val['rid']];
            if(ml_tool_resid::resid2type($val['rid'])==ML_RESID_TYPE_USERFEED){
                $val['comData']=$feedData[$val['rid']];
            }
            $val['nicks']=$this->_nicks;
            $val['goodUrls']=$this->_goodUrls;
            $val['personUrls']=$this->_personUrls;
            $val['personPics']=$this->_personPics;
            $val['pic_urls']=$this->_pic_urls;
            $val['pic_urls_big']=$this->_pic_urls_big;
            $val['goodPrice']=$this->_goodPrice;
            $val['goodTitle']=$this->_goodTitle;
            $val['count']=$count;
            $aHtml[] = ml_tool_template::parseModTpl($val , '702');
        }
        return $aHtml;
    }
    
  
    public function getIds($data){
        foreach ($data as $val){
            if(!empty($val['uid'])){
                $this->_uids[]=$val['uid'];
            }
            if(!empty($val['act_uid'])){
                $this->_uids[]=$val['act_uid'];
            }
            if(!empty($val['pic_id'])){
                $this->_pic_ids[]=$val['pic_id'];
            }
        }
    }
    public function getPersonUrls($uids){
        foreach($uids as $val){
            $this->_personUrls[$val]=ml_tool_urlMaker::person_index($val);
        }
    }
    public function getPersonPics($uids){
        foreach($uids as $val){
            $this->_personPics[$val]=ml_tool_picid::uid2portrait($val);
        }
    }
    public function getPicUrls($pic_ids){
        foreach($pic_ids as $val){
            $this->_pic_urls[$val]=ml_tool_picid::pid2url($val,ML_USER_PICSIZE_FEED,ML_PICTYPE_CONTENT);
            $this->_pic_urls_big[$val]=ml_tool_picid::pid2url($val,ML_USER_PICSIZE_SHOW,ML_PICTYPE_CONTENT);
        }
    }
    public function getGoodUrls($rids){
        foreach($rids as $val){
            $this->_goodUrls[$val]=ml_tool_urlMaker::show_goods($val);
        }
    }
    
    public function getGoodPrice($rids){
        foreach ($rids as $val){
            $this->_goodPrice[$val]=ml_tool_standardShow::rmb_price($this->contData[$val]['gd_price']);
        }
    }
    public function getGoodTitle($rids){
        foreach ($rids as $val){
            $this->_goodTitle[$val]=$this->contData[$val]['gd_title'];
        }
    }    
    public function makeTitle($att){
        $rs='';
        switch ($att) {
            case '0':
                $rs="不感冒";
                break;
            case '1':
                $rs="可以有";
                break;
            case '2':
                $rs="长草了";
                break;
            case '3':
                $rs="喜欢";
                break;
        }
        return $rs;
    }
    public function makeTag($content){
        $tagArr=explode(',',$content);
        $content='';
        foreach($tagArr as $tag){
            $content.='  <a target="_blank"  class="ml_linka" href=" "> "'.$tag.'" </a>  ';
        }
        return '我刚刚添加了我的标签：'.$content;
    }
    public function getFeedContent(&$feedData){
        foreach($feedData as &$val){
            $val['content']=ml_tool_formatContent::format_content($val['content']);
            switch($val['type']){
                case ML_FEED_TYPE_MOD_DEC:
                    $val['content']='修改美啦签名为：'.$val['content'];
                    break;
                case ML_FEED_TYPE_ATTITUDE:
                    $val['comment']=$this->makeTitle($val['feed_info']['attitude']);
                    $cont=$this->contData[$val['feed_info']['rid']];
                    $val['content']=$cont['content'];
                    $val['pic_id']=$cont['pic_id'];
                    break;
                case ML_FEED_TYPE_MOD_TAG:
                    $val['content']=$this->makeTag($val['content']);
                    break;
                case ML_FEED_TYPE_REPOST_COLLECTION:
                    $url=ml_tool_urlMaker::col_content($val['feed_info']['col_id'],$val['uid']);
                    $val['comment']=$val['content'].'--收集到<a target="_blank" class="ml_linka" href="'.$url.'">【'.$val['feed_info']['col_name'].'】</a>专辑中';
                    $cnt=$this->contData[$val['feed_info']['rid']];
                    $val['content']=$cont['content'];
                    $val['pic_id']=$cont['pic_id'];
                    break;
            }
            if(count($cont)!=0){
                $conUid=$cont['uid'];
            }else{
                $conUid=$val['uid'];
            }
            
            if(!empty($val['content'])){
                $nick=$this->getNickHtml($conUid);
                $val['content']=$nick.$val['content'];
            }
            
            if(!empty($val['comment'])){
                $nick=$this->getNickHtml($val['uid']);
                $val['comment']=$nick.$val['comment'];
            }
            unset($val);
        }
        return $feedData;
    }
    
    public function getNickHtml($conUid){
        return '<a  uid="'.$conUid.'" usercard="true"  target="_blank" class="ml_linka" target="_blank" href="'.ml_tool_urlMaker::person_index($conUid).'"> @'.$this->_nicks[$conUid].'</a>   :   ';
    } 
    public function getComCountNum($aRid){
        if(!isset($oRedis)){
            $oRedis=new ml_model_rdsCount();
        }
        $rs = $oRedis->getCommentCount($aRid);
        if(!$rs)  return false;
        $count=$oRedis->get_data();
        return $count;
    }
    
    public function getContData(&$contData){
        foreach($contData as &$val){
            $val['content']=ml_tool_formatContent::format_content($val['content']);
            $nick='<a  target="_blank" class="ml_linka" uid="'.$val['uid'].'" usercard="true" href="'. ml_tool_urlMaker::person_index($val['uid']).'"> @'.$this->_nicks[$val['uid']].'</a> : ';
            $val['content']=$nick.$val['content'];
            unset($val);
        }
        return $contData;
    }
    
}







